#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vvector>

using namespace std;

class Solution {
    int  dp[5000];
public:
    int knapsack(int V, int n, vector<vector<int> >& vw) {

        for (int i = 0; i < n;i++)
        {
            for (int j = V;j >= vw[i][0];j--)
            {
                dp[j] = max(dp[j], dp[j - vw[i][0]] + vw[i][1]);
            }
        }

        return dp[V];
    }
};